#include <iostream>
#include <SDL2/SDL.h>

#include "Window.hpp"
#include "GuiMain.hpp"

int main(int argc, char *argv[])
{
    if(SDL_Init(SDL_INIT_VIDEO))
    {
        std::cerr << "Could not initialize SDL: " << SDL_GetError();
        return 0;
    }

    std::cout << "Initialized SDL2\n";

    Window *window = new Window();
    if(!window->Create("Spirit", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1024, 768, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS))
    {
        std::cerr << "Could not create Window: " << SDL_GetError();
        SDL_Quit();
        return 0;
    }

    std::cout << "Created window\n";

    GuiMain *guiMain = new GuiMain(window->GetSize());
    guiMain->Initialize(window->GetRenderer());

    SDL_Event event;
    bool quit = false;

    while(!quit)
    {
        while(SDL_PollEvent(&event))
        {
            if(event.type == SDL_QUIT)
            {
                quit = true;
            }
        }

        guiMain->Render();
    }

    guiMain->Destroy();
    window->Destroy();
    SDL_Quit();

    std::cout << "Ended.\n";

    return 0;
}
